<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.Company"%>
<%@page import="db.CompanyDAO"%>
<%@page import="db.Place"%>
<%@page import="db.PlaceDAO"%>
<%@ include file="/jsp/common/utility/logined.jsp" %>
<%
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	CompanyDAO companyDAO = (CompanyDAO)ctx.getBean("CompanyDAO");
		PlaceDAO placeDAO = (PlaceDAO)ctx.getBean("PlaceDAO");
	request.setCharacterEncoding("utf-8");
	String cid = request.getParameter("cid");
	
	int id = 0;
	if(cid!=null || !"".equals(cid)){
		id = Integer.parseInt(cid);
	}
	String message = "";
	
	String type = request.getParameter("type");
	//type=2提交表单
	if(type!=null && (type=="2" || "2".equalsIgnoreCase(type))){
		//System.out.println("提交");
		request.setAttribute("type",2);
		String name = request.getParameter("cname");
		
		
		Place place = new Place();
		place = placeDAO.findById(id);
		//判断登录名是否为空，是否重复
		if(name==null || "".equals(name)){
			message = "修改库位失败，库位信息不能为空。";
			request.setAttribute("message",message);
			request.setAttribute("suess",false);
			pageContext.forward("/vm/place/mod_coninfo.vm");
			return;
		}else{
			if((name == place.getName() || name.equals(place.getName()))){
				message = "施工单位名称未做修改！";
			}else{
				List md = placeDAO.findByName(name);
				if(md != null && md.size() > 0 ){
					message = "修改库位信息失败，库位信息已经存在。";
					request.setAttribute("suess",false);
					request.setAttribute("message",message);
					pageContext.forward("/vm/place/mod_coninfo.vm");
					return;
				}
			}
		}

		place.setName(name);
		placeDAO.attachDirty(place);
		
		//System.out.println(uid);
		message = "恭喜您！修改库位信息成功！";
		request.setAttribute("message",message);
		request.setAttribute("suess",true);
		request.setAttribute("cid",id);
		pageContext.forward("/vm/place/mod_coninfo.vm");
		return;
		
		
	}else{
	//正常显示
		//System.out.println("显示");
		Place place = new Place();
		place = placeDAO.findById(id);
		
		request.setAttribute("place",place);
		request.setAttribute("type",1);
		request.setAttribute("cid",id);
		pageContext.forward("/vm/place/mod_coninfo.vm");
		
	}
	
%>
